﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EnterpriseFramework.DataAccess;
using System.Xml;
using System.Data.SqlClient;
using System.Diagnostics;

namespace Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();


        }

        static string connString;

        private void button1_Click(object sender, EventArgs e)
        {
            
            Stopwatch st2 = new Stopwatch();
            st2.Start();
            if (string.IsNullOrEmpty(connString))
            {
                XmlDocument config = null;
                config = new XmlDocument();
                config.Load("Config.config");
                XmlNodeList nodes = config.SelectNodes("//" + "Providers")[0].SelectNodes("//" + "Provider");
                connString = nodes[0]["ConnectionString"].InnerText;
            }
            SqlConnection conn = new SqlConnection(connString);
            conn.Open();
            SqlCommand cmd = new SqlCommand("Select Unit_ID,Unit_Name FROM UNIT", conn);
            DataTable dt = new DataTable();
            dt.Load(cmd.ExecuteReader());
            st2.Stop();

            Stopwatch st1 = new Stopwatch();
            st1.Start();
            //List<Unit> list = new List<Unit>();
            Entities<Unit> ent = new Entities<Unit>();
            ELAdapter<Unit> r = new ELAdapter<Unit>();
            //Query q = new Query();
            //q.Columns(Unit.Col_Unit_Name);
            //string ssss = Unit.Col_Unit_Name;
            //DataTable dt = new DataTable();
            //q.OrderBy(Unit.Col_Unit_Name.Ascending);
            ent = r.Select().DataAsList();
            st1.Stop();
            //ent = r.Select(q.Where(Unit.Col_Unit_Name.Like("%gogo%"))).DataAsList();
            //ent[1].Unit_Name = "uuuuuuuuuuuuuuu";
            //dt = r.Select().DataAsDataTable();
            //list = r.Select(q.Where("Unit_Name=@", new Parameter(DbType.String, "gogo"))).DataAsList();

            

            MessageBox.Show("My: "+st1.Elapsed.ToString() + "\nDataTable: " + st2.Elapsed.ToString());
        }
    }
}
